//判断是否为空
function isBlank(value) {
    return !value || !/\S/.test(value)
}

$(function(){  
    var token = $("meta[name='_csrf']").attr("content");  
    var header = $("meta[name='_csrf_header']").attr("content");  
    $.ajaxSetup({   
       	beforeSend: function (xhr) {  
       		xhr.setRequestHeader(header, token);  
     	},
    }); 
    // 不支持placeholder浏览器下对placeholder进行处理
    if (document.createElement('input').placeholder !== '') {
        $('[placeholder]').focus(function () {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                input.val('');
                input.removeClass('placeholder');
            }
        }).blur(function () {
            var input = $(this);
            if (input.val() == '' || input.val() == input.attr('placeholder')) {
                input.addClass('placeholder');
                input.val(input.attr('placeholder'));
            }
        }).blur().parents('form').submit(function () {
            $(this).find('[placeholder]').each(function () {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }
            });
        });
    }
});

//重写alert
window.alert = function(msg, callback){
	parent.layer.alert(msg, function(index){
		parent.layer.close(index);
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}
window.msg =  function(msg, callback){
	parent.layer.msg(msg, {icon: 6,time:2000},function(){
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}
 
//重写confirm式样框
window.confirm = function(msg, callback){
	parent.layer.confirm(msg, {btn: ['确定','取消']},
	function(){//确定事件
		if(typeof(callback) === "function"){
			callback("ok");
		}
	});
}

//选择一条记录
function getSelectedRow() {
    var grid = $("#jqGrid");
    var rowKey = grid.getGridParam("selrow");
    if(!rowKey){
    	alert("请选择一条记录");
    	return ;
    }
    
    var selectedIDs = grid.getGridParam("selarrrow");
    if(selectedIDs.length > 1){
    	alert("只能选择一条记录");
    	return ;
    }
    
    return selectedIDs[0];
}

/**
 * 简单类型数组
 * @param arr
 * @param val
 * @returns
 */
function removeByValue(arr,val){
	if(arr && val){
		for(var i=0;i<arr.length;i++){
			if(arr[i]==val){
				arr.splice(i,1);
				break;
			}
		}
	}
}

//选择多条记录
function getSelectedRows() {
	 var grid = $("#jqGrid");
    var rowIds = grid.getGridParam("selarrrow");
    if(!rowIds || rowIds.length==0){
    	alert("请选择一条记录");
    	return;
    }
    return rowIds;
}

//判断是否为空
function isBlank(value) {
    return !value || !/\S/.test(value)
}